package me.xiaosiqi.syt.hosp.service.impl;

import me.xiaosiqi.syt.hosp.repository.HospitalRepository;
import me.xiaosiqi.syt.hosp.service.HospitalService;
import me.xiaosiqi.syt.model.hosp.Hospital;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @author: xiaosiqi
 * @date:2022/7/31 15:00
 */
@Service
public class HospitalServiceImpl implements HospitalService {

    @Autowired
    private HospitalRepository hospitalRepository;

    @Override
    public void saveHospital(Hospital hospital) {
        Hospital hospitalExist = hospitalRepository.getHospitalByHoscode(hospital.getHoscode());
        if (null != hospitalExist) {
            hospital.setId(hospitalExist.getId());
            hospital.setStatus(hospitalExist.getStatus());
            hospital.setCreateTime(hospitalExist.getCreateTime());
            hospital.setUpdateTime(new Date());
            hospital.setIsDeleted(0);
            hospitalRepository.save(hospital);
        } else {
            hospital.setStatus(0);
            hospital.setCreateTime(new Date());
            hospital.setUpdateTime(new Date());
            hospital.setIsDeleted(0);
            hospitalRepository.save(hospital);
        }
    }

    @Override
    public Hospital getByHoscode(String hoscode) {
       return hospitalRepository.getHospitalByHoscode(hoscode);
    }
}
